﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;

public partial class SpecialPlan_ModifySpecialPlanDetail : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (!IsPostBack)
        {
            Bind();
        }
    }

    void Bind()
    {
        object[] _value = new object[1];
        _value[0] = Utility.HttpHelp.getParamsInt("SpecialPlanDetailId");
        this.txtSpecialPlanSortId.Value = Utility.HttpHelp.getParamsString("SpecialPlanDetailSortId");
        DataTable specialPlan = new BLL.SpecialPlan().GetSpecialPlanDetailById(_value);

        if (specialPlan.Rows.Count > 0)
        {
            this.txtCompleteTime.Text = Convert.ToDateTime(specialPlan.Rows[0]["CompleteTime"]).ToShortDateString();
            this.txtStartTime.Text = Convert.ToDateTime(specialPlan.Rows[0]["StartTime"]).ToShortDateString();

            this.txtMasterPeople.Value = specialPlan.Rows[0]["MasterPeople"].ToString();
            this.txtMasterDepartment.Text = specialPlan.Rows[0]["MasterDepartment"].ToString();
            this.txtSpecialPlanSortId.Value = specialPlan.Rows[0]["SpecialPlanDetailSortId"].ToString();

            this.txtSlaveDepartment.Value = specialPlan.Rows[0]["SlaveDepartment"].ToString();
            this.txtSlaveDepartmentDuty.Text = specialPlan.Rows[0]["SlaveDepartmentDuty"].ToString();
            this.txtEvaluatePeople.Value = specialPlan.Rows[0]["EvaluatePeople"].ToString();

            this.txtWorkItem.Text = specialPlan.Rows[0]["WorkItem"].ToString();
            this.txtPreposeTask.Text = specialPlan.Rows[0]["PreposeTask"].ToString();
            this.txtRemark.Text = specialPlan.Rows[0]["Remart"].ToString();

            this.drpPriorityLevel.SelectedIndex = this.drpPriorityLevel.Items.IndexOf(this.drpPriorityLevel.Items.FindByText(specialPlan.Rows[0]["PriorityLevel"].ToString()));

        }
    }

    /// <summary>
    /// 判断控件值是否为空
    /// </summary>
    /// <returns>空返回0，有值返回1</returns>
    /// <author>gzz</author>
    /// <date>2009-3-19 </date>
    string isNull()
    {
        #region 验证是否为空
        if (this.txtSpecialPlanSortId.Value.Length == 0)
        {
            return "专项计划编号不可为空";
        }
        if (this.txtCompleteTime.Text.Length == 0)
        {
            return "完成时间不可为空";
        }
        if (this.txtMasterPeople.Value.Length == 0)
        {
            return "负责人不可为空";
        }
        if (this.txtWorkItem.Text.Length == 0)
        {
            return "计划名称不可为空";
        }
        if (this.txtSlaveDepartment.Value.Length == 0)
        {
            return "配合部门不可为空";
        }
        if (this.txtSlaveDepartmentDuty.Text.Length < 18 && this.txtSlaveDepartment.Value != "独立完成")
        {
            return "配合部门责任不可为空";
        }
        if (this.txtStartTime.Text.Length == 0)
        {
            return "开始时间不可为空";
        }
        if (this.txtEvaluatePeople.Value.Length == 0)
        {
            return "评估人不可为空";
        }
        return "";
        #endregion
    }

    /// <summary>
    /// 时间验证
    /// </summary>
    bool verifyDate()
    {
        #region 必要验证判断
        //判断完成时间是否大于起始时间

        DateTime _startTime = Convert.ToDateTime(this.txtStartTime.Text.Trim());
        DateTime _endTime = Convert.ToDateTime(this.txtCompleteTime.Text.Trim());
        if (_startTime >= _endTime)
        {
            Utility.HttpHelp.alert("完成时间需要大于起始时间", Page);
            return false;
        }
        return true;
        #endregion
    }

    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModify_Click(object sender, EventArgs e)
    {
        string alert = isNull();
        if (alert.Length > 0)
        {
            Utility.HttpHelp.alert(alert, Page);
            return;
        }
        else
        {
            if (this.txtSpecialPlanSortId.Value.Length == 0)
            {
                Utility.HttpHelp.alert("计划编号只能从1开始！", Page);
                return;
            }
            if (this.txtMasterPeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("责任人不可为多人！", Page);
                return;
            }
            if (this.txtEvaluatePeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("评估人不可为多人！", Page);
                return;
            }

            DataTable specialPlan = new BLL.SpecialPlan().GetSpecialPlanDetailBySpecialId(new object[] { Utility.HttpHelp.getParamsInt("SpecialPlanDetailId") });


            object[] _value = new object[22];
            _value[0] = Utility.HttpHelp.getParamsInt("SpecialPlanDetailId");
            _value[1] = this.txtSpecialPlanSortId.Value;
            _value[2] = this.txtWorkItem.Text;
            _value[3] = Convert.ToDateTime(this.txtStartTime.Text);
            _value[4] = Convert.ToDateTime(this.txtCompleteTime.Text);
            _value[5] = this.txtMasterDepartment.Text;
            _value[6] = this.txtMasterPeople.Value;
            _value[7] = this.txtSlaveDepartment.Value;
            _value[8] = this.txtSlaveDepartmentDuty.Text;
            _value[9] = this.txtEvaluatePeople.Value;
            _value[10] = string.Empty;
            _value[11] = string.Empty;
            _value[12] = Convert.ToInt32(specialPlan.Rows[0]["State"]);
            _value[13] = this.drpPriorityLevel.SelectedItem.Text;
            _value[14] = string.Empty;
            _value[15] = specialPlan.Rows[0]["CompleteState"].ToString();
            _value[16] = specialPlan.Rows[0]["CompleteDesc"].ToString();
            _value[17] = specialPlan.Rows[0]["VerifyPeople"].ToString();
            _value[18] = Convert.ToInt32(specialPlan.Rows[0]["VerifyCircuitId"]);
            _value[19] = specialPlan.Rows[0]["Sponsor"].ToString();
            _value[20] = this.txtPreposeTask.Text;
            _value[21] = this.txtRemark.Text;
            int result = new BLL.SpecialPlan().EditSpecialPlanDetailById(_value);
            if (result == 0)
            {
                Utility.HttpHelp.alert("修改专项计划未成功，请重试！", Page);
            }
            else
            {
                string url = Utility.HttpHelp.getParamsString("url");
                string Department = Utility.HttpHelp.getParamsString("Department");
                if (url.Length > 0)
                {
                    Utility.HttpHelp.closeWindow(url + "?SpecialPlanId=" + Utility.HttpHelp.getParamsString("SpecialPlanId") + "&Department=" + Department, Page);
                }
                else
                {
                    Utility.HttpHelp.closeWindow("SpecialPlanResolveAdd.aspx?SpecialPlanId=" + Utility.HttpHelp.getParamsString("SpecialPlanId"), Page);
                }

            }
        }
    }
}